from collections import defaultdict

class Solution():
    def __init__(self, grid, N, M):
        self.grid = grid
        self.N = N
        self.M = M
        self.num_grid = [[0]*M for _ in range(N)]
        self.num_area = defaultdict(int)
        self.visited = [[False]*M for _ in range(N)]
        self.direct = [(-1, 0), (0, -1), (1, 0), (0, 1)]
        self.max_area = 0
        
    def dfs(self, x, y, num):
        self.visited[x][y] = True
        self.num_area[num] += 1
        self.num_grid[x][y] = num
        
        for i, j in self.direct:
            next_x = x+i
            next_y = y+j
            if (
                0<=next_x<self.N
                and 0<=next_y<self.M
                and not self.visited[next_x][next_y]
                and self.grid[next_x][next_y] == 1
                ):
                self.dfs(next_x, next_y, num)
    
    def comp_area(self):
        num = 0
        for i in range(self.N):
            for j in range(self.M):
                if self.grid[i][j] == 1 and not self.visited[i][j]:
                    num += 1
                    self.dfs(i, j, num)
    
    def cur_area(self, x, y):
        result = 1
        num_set = set()
        for i,j in self.direct:
            next_x = x+i
            next_y = y+j
            if 0<=next_x<self.N and 0<=next_y<self.M:
                if self.num_grid[next_x][next_y] in num_set :
                    continue
                else:
                    num_set.add(self.num_grid[next_x][next_y])
                    result += self.num_area[self.num_grid[next_x][next_y]]
        return result
        
    
    def add_area(self):
        if len(grid) == 1 and len(grid[0]) ==1:
            return 1
        
        for i in range(self.N):
            for j in range(self.M):
                if self.grid[i][j] == 0:
                    self.max_area = max(self.max_area, self.cur_area(i,j))
        
        if self.max_area == 0:
            return max(self.num_area.values())
            
        return self.max_area
                    
if __name__ == "__main__":
    N,M = map(int, input().split())
    grid = []
    for i in range(N):
        grid.append(list(map(int, input().split())))
    
    solution = Solution(grid, N, M)
    solution.comp_area()
    print(solution.add_area())
    
    